<?php
namespace RTSCraft\MainBundle\Controller\Util;

/*
 * Some useful functions
 */
class AuthUtil
{
  /*
   * check if the user is authenticated (i.e admin)
   * Parameter : A controller.
   * Returns : 0 => ok, else error. (100 - 102)
   */
  public static function is_auth($controller)
  {
    $session = $controller->get("session");

      /* check timeout */
      if ((!$session->has("timeout")) || (!$session->has("isAdmin")))
	{
	  return 100;
	}

      $now = time();
      if ($now > $session->get("timeout"))
	{
	  return 101;
	}

      if ($session->get("isAdmin") == false)
	{
	  return 102;
	}

      return 0;
  }
}